<template>
  <view class="index_container">
    <home-page v-if="currentTab === 0" />
    <category-page v-else-if="currentTab === 1" />

    <!-- 自动化 -->
    <automation-config v-else-if="currentTab === 2" />

    <me-page v-else-if="currentTab === 3" :userInfo="userInfo" />

    <custom-tabbar />
  </view>
</template>

<script>
import customTabbar from "@/components/custom-tabbar/index.vue";
import { mapGetters } from "vuex";
import homePage from "@/pages/home/index.vue";
import categoryPage from "@/pages/category/index.vue";
import automationConfig from "@/pages/automationConfig/index";
import mePage from "@/pages/me/index.vue";

export default {
  components: {
    customTabbar,
    homePage,
    categoryPage,
    automationConfig,
    mePage,
  },
  computed: {},
  data() {
    return {
      // 页面参数
      options: {},
      // 是否已登录
      isLogin: false,
      userInfo: {},
    };
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const app = this;
    // 微信一键登陆
    uni.login({
      provider: "weixin",
      success: (res) => {
        console.log(res);
        // 获取用户信息
        uni.getUserInfo({
          provider: "weixin",
          success: (res) => {
            console.log("getUserInfo=>", res);
            app.userInfo = res.userInfo;
          },
        });
      },
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},
  computed: {
    ...mapGetters(["currentTab"]),
  },
  watch: {},

  methods: {
    click(item) {
      console.log("item", item);
    },

    goToDeviceInfo(id) {
      uni.navigateTo({
        url: `/pages/index/deviceInfo/index?id=${id}`,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.index_container {
  height: calc(100% - 105px - 35.045rpx);
}
</style>
